/**
 * 
 */
package com.lehecai.core.api.event;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;

/**
 * 用户道具
 * @author He Wang
 *
 */
public class PropExchangeCard extends AbstractApiResultBean {
	
	public static final String QUERY_EVENT_ID = "event_id";
    public static final String QUERY_CREATE_DATE = "create_at";
	
	public static final String SET_PROP_ID = "prop_id";
	public static final String SET_NUMBER = "number";
	public static final String SET_EVENT_ID = "event_id";
	public static final String SET_EXPIRE = "expire_at";
	

	private Long id;		       //编码
	private String cardNo;         //兑换卡号
	private String secret;	       //兑换卡密码
	private PropExchangeCardVerifyMode verifyMode;    //验证模式
	private Date createdTime;      //创建时间
	private Date expireTime;       //过期时间
	private Date claimTime;        //使用时间 
	private Long propId;           //道具id
	private Long eventId;          //活动id
	private PropExchangeCardStatus status;//道具类型名称
	private String eventName;      //活动名称
	private String propName;       //道具名称
	
	private Integer number;        //生成个数

	public static PropExchangeCard convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		PropExchangeCard card = new PropExchangeCard();
		card.id = getLong(object, "id");
		card.cardNo = getString(object, "card_no");
		card.secret = getString(object, "secret");
		card.verifyMode = PropExchangeCardVerifyMode.getItem(getInt(object, "verify_mode"));
		card.createdTime = CoreDateUtils.parseDate(getString(object, "create_at"), CoreDateUtils.DATETIME);
		card.expireTime = CoreDateUtils.parseDate(getString(object, "expire_at"), CoreDateUtils.DATETIME);
		card.claimTime = getString(object, "claim_at").equals("0000-00-00 00:00:00") ? null : CoreDateUtils.parseDate(getString(object, "claim_at"), CoreDateUtils.DATETIME);
		card.propId = getLong(object, "prop_id");
		card.eventId = getLong(object, "event_id");
		card.status = PropExchangeCardStatus.getItem(getInt(object, "status"));
		card.eventName = getString(object, "event_name");
		card.propName = getString(object, "prop_name");
		return card;
	}
	
	public static List<PropExchangeCard> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<PropExchangeCard> list = new ArrayList<PropExchangeCard>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public PropExchangeCardVerifyMode getVerifyMode() {
		return verifyMode;
	}

	public void setVerifyMode(PropExchangeCardVerifyMode verifyMode) {
		this.verifyMode = verifyMode;
	}

	public Date getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(Date expireTime) {
		this.expireTime = expireTime;
	}

	public Date getClaimTime() {
		return claimTime;
	}

	public void setClaimTime(Date claimTime) {
		this.claimTime = claimTime;
	}

	public Long getPropId() {
		return propId;
	}

	public void setPropId(Long propId) {
		this.propId = propId;
	}

	public Long getEventId() {
		return eventId;
	}

	public void setEventId(Long eventId) {
		this.eventId = eventId;
	}

	public PropExchangeCardStatus getStatus() {
		return status;
	}

	public void setStatus(PropExchangeCardStatus status) {
		this.status = status;
	}

	public void setNumber(Integer number) {
		this.number = number;
	}

	public Integer getNumber() {
		return number;
	}

	public void setEventName(String eventName) {
		this.eventName = eventName;
	}

	public String getEventName() {
		return eventName;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setPropName(String propName) {
		this.propName = propName;
	}

	public String getPropName() {
		return propName;
	}



}
